#ifndef FFMPEGEXTRA_EYERWASMINDEXEDDB_GETEVENT_HPP
#define FFMPEGEXTRA_EYERWASMINDEXEDDB_GETEVENT_HPP

#include "EyerWASMCommon/EyerWASMEvent.hpp"
#include "EyerWASMCommon/EyerWASMBuffer.hpp"

namespace Eyer
{
    class EyerWASMIndexedDB_GetEvent : public EyerWASMEvent
    {
    public:
        EyerWASMIndexedDB_GetEvent(
                int indexedDBKey,
                const std::string & key
                );
        ~EyerWASMIndexedDB_GetEvent();

        virtual int Run() override;

        int EyerWASMIndexedDB_GetEvent_Get_OnSucc(
                uint8_t * buf,
                int bufSize,
                int64_t contentLength,
                int64_t rangeLength);
        int EyerWASMIndexedDB_GetEvent_Get_OnSucc_No_Found();
        int EyerWASMIndexedDB_GetEvent_Get_OnFail();

        EyerWASMBuffer GetBuffer();
        int64_t GetContentLength();
        int64_t GetRangeLength();

        bool IsFound();

    private:
        int m_indexedDBKey = 0;
        std::string m_key;

        EyerWASMBuffer m_buffer;
        int64_t m_contentLength = 0;
        int64_t m_rangeLength = 0;

        std::atomic<bool> m_isFound {false};
    };
}

#endif //FFMPEGEXTRA_EYERWASMINDEXEDDB_GETEVENT_HPP
